'use strict';

const Controller = require('../base');

class SysRegisterController extends Controller {

  async create() {
    const { ctx } = this;
    const body = ctx.request.body;

    ctx.validate({
      username: { type: 'string', required: true },
      name: { type: 'string', required: true },
      // roles: { type: 'array', required: true },
    }, body);

    const res = await ctx.service.sys.register.create(body);
    if (res) {
      this.success('注册成功');
    } else {
      this.error('注册失败 ' + (res.msg || ''));
    }
  }
}

module.exports = SysRegisterController;
